package com.zy.springboot_nahua4.controllers;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;

public class GlobalExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    public ResponseEntity<ResponseResult>handleRuntimeException(RuntimeException ex){
        ex.printStackTrace();
        return new ResponseEntity<>(
                ResponseResult.error("服务器出现运行时错误，有可能是参数类型错误："+ex.getMessage()),
                HttpStatus.BAD_REQUEST);

    }

    @ExceptionHandler(Exception.class)
    public ResponseEntity<ResponseResult>handleAllException(Exception ex){
        ex.printStackTrace();
        return new ResponseEntity<>(
                ResponseResult.error("服务器出现致命错误："+ex.getMessage()),
                HttpStatus.INTERNAL_SERVER_ERROR
        );
    }
}
